package hn.cch.http.server;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;

/**
 * HTTP事件通道
 */
public class HttpChannel extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {

        // HttpServer接收httpRequest要使用HttpRequestDecoder进行解码
        ch.pipeline().addLast(new HttpRequestDecoder());
        // HttpServer发送httpResponse要使用HttpResponseEncoder进行编码
        ch.pipeline().addLast(new HttpResponseEncoder());
        // HttpServer接收httpRequest请求使用HTTP事件处理发送httpResponse响应
        ch.pipeline().addLast(new HttpHandler());
    }
}
